cmake_minimum_required(VERSION 2.8)
project(network)

set(CMAKE_VERBOSE_MAKEFILE on)

if (DEFINED release)
  if (${release} EQUAL 1)
    add_definitions(-DNDEBUG)
  endif()
endif()

set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS "-std=c++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall")
set(PROJECT_DIST_DIR "${PROJECT_SOURCE_DIR}/bin")

#set(LIBPROTO_FIXED -Wl,--whole-archive proto -Wl,--no-whole-archive)

#add_definitions(-g -Wall -Werror -rdynamic -fPIC -std=c++0x)
#add_definitions(-pipe -D_NEW_LIC -D_GNU_SOURCE -D_REENTRANT)
#add_definitions(-fno-strict-aliasing -Winvalid-pch)

# the following logic defines a macro called __FILENAME__, who's value is relative path to the source file
# why we define this macro but does not just use __FILE__, is because with cmake, the generated compilation
# path is always absolute, like:
#     /usr/bin/c++ ... /absolute/path/to/the/source/file
# so, the __FILE__ will be the absolute path, however, when do do logging, we don't want to log such a long
# path, so we remove the prefix CMAKE_SOURCE_DIR and just leave the relative path to __FILENAME__
#
# the following is not perfect, the macro used in header files will be replaced by source file names, that's
# more serious than the long file name, so we just use __FILE__ again.
#
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")

file(GLOB_RECURSE SRC_LIST *.h *.c *.cpp)
list(APPEND SRC_LIST)

set(EXECUTABLE_OUTPUT_PATH "${PROJECT_DIST_DIR}")

#include_directories("/home/xcy/workspace/trunk/Server/src/libsk")
#include_directories("/home/xcy/workspace/trunk/Server/src/common")
#include_directories("/home/xcy/workspace/trunk/Server/src/proto")
#include_directories("/home/xcy/workspace/trunk/Server/src/service/client")
#include_directories("/home/xcy/workspace/trunk/Server/src/resource")
include_directories("/home/xcy/workspace/trunk/Server/src/deps/gdk/include")
#include_directories("/home/xcy/workspace/trunk/Server/src/deps/libuv/include")
#include_directories("/home/xcy/workspace/trunk/Server/src/deps/spdlog/include")
#include_directories("/home/xcy/workspace/trunk/Server/src/deps/protobuf/include")

link_directories("/home/xcy/workspace/trunk/Server/src/deps/gdk/lib")
#link_directories("/home/xcy/workspace/trunk/Server/src/deps/protobuf/lib")
#link_directories("/home/xcy/workspace/trunk/Server/src/deps/libuv/lib")

add_executable(networkd ${SRC_LIST})
target_link_libraries(networkd uv gdk_ConsoleLog gdk_SimpleNetwork gdk_net gdk_core lzo2 ssl crypto pthread)
#target_link_libraries(network ${LIBPROTO_FIXED} protobuf uv gdk_ConsoleLog gdk_SimpleNetwork gdk_net gdk_core lzo2 ssl crypto pthread)
